project(build_tests)
message(STATUS "PROJECT_NAME:${PROJECT_NAME}")

message(STATUS "CMAKE_BUILD_TYPE:${CMAKE_BUILD_TYPE}")

execute_process(
    COMMAND date +%Y-%m-%d
    OUTPUT_VARIABLE BUILD_TIME
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "BUILD_TIME:${BUILD_TIME}")

execute_process(
    COMMAND git rev-parse --abbrev-ref HEAD
    OUTPUT_VARIABLE GIT_BRANCH
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "GIT_BRANCH:${GIT_BRANCH}")

execute_process(
    COMMAND git rev-parse --short HEAD
    OUTPUT_VARIABLE GIT_COMMIT_ID
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "GIT_COMMIT_ID:${GIT_COMMIT_ID}")

set(VERSION_ID ${BUILD_TIME}--${GIT_BRANCH}--${GIT_COMMIT_ID}--${CMAKE_BUILD_TYPE})
message(STATUS "VERSION_ID:${VERSION_ID}")

# compiler
set(CMAKE_C_COMPILER  "gcc")
set(CMAKE_CXX_COMPILER  "g++")

message(STATUS "CMAKE_C_COMPILER:${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER:${CMAKE_CXX_COMPILER}")

# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -ffunction-sections -fdata-sections -Wl,--gc-sections -DCS_ENABLE_DEBUG")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ffunction-sections -fdata-sections -Wl,--gc-sections -DCS_ENABLE_DEBUG")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -ffunction-sections -fdata-sections -Wl,--gc-sections -rdynamic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ffunction-sections -fdata-sections -Wl,--gc-sections -rdynamic")
add_definitions(-DVERSION_ID=\"${VERSION_ID}\")

set(CMAKE_CXX_STANDARD 11)

include_directories(${CMAKE_HOME_DIRECTORY}/src)

# rpath 方式优先，其次LD_LIBRARY_PATH方式
link_directories(${CMAKE_HOME_DIRECTORY}/build/build_tests)

aux_source_directory(${CMAKE_HOME_DIRECTORY}/src SRC_FILES)
# message(STATUS "SRC_FILES:${SRC_FILES}")

add_library(loger SHARED ${SRC_FILES})

set(TEST_STDOUT_LOGER_EXE test_stdout_loger.exe)
add_executable(${TEST_STDOUT_LOGER_EXE} ${CMAKE_HOME_DIRECTORY}/tests/test_stdout_loger.cpp)
target_link_libraries(${TEST_STDOUT_LOGER_EXE} loger pthread)

set(TEST_SINGLE_FILE_LOGER_EXE test_single_file_loger.exe)
add_executable(${TEST_SINGLE_FILE_LOGER_EXE} ${CMAKE_HOME_DIRECTORY}/tests/test_single_file_loger.cpp)
target_link_libraries(${TEST_SINGLE_FILE_LOGER_EXE} loger pthread)

set(TEST_CHUNK_FILE_LOGER_EXE test_chunk_file_loger.exe)
add_executable(${TEST_CHUNK_FILE_LOGER_EXE} ${CMAKE_HOME_DIRECTORY}/tests/test_chunk_file_loger.cpp)
target_link_libraries(${TEST_CHUNK_FILE_LOGER_EXE} loger pthread)

set(TEST_ROLL_FILE_LOGER_EXE test_roll_file_loger.exe)
add_executable(${TEST_ROLL_FILE_LOGER_EXE} ${CMAKE_HOME_DIRECTORY}/tests/test_roll_file_loger.cpp)
target_link_libraries(${TEST_ROLL_FILE_LOGER_EXE} loger pthread)
